<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>binder</title>
    <!--css+div原生页面以script src的方式继承vue和axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>

    <!--通过common.js完成axios的全局配置-->
    <script src="js/common.js"></script>
</head>
<body>
    <div id="myDiv"></div>
    <script type="text/javascript">
        new Vue({
            el:"#myDiv",
            data:{
            },
            methods:{
            },
            mounted(){
                /*
                //http://bugtracker.itsource.cn/callback.html?code=011JBI0w32eRLW2U6j4w34klDx4JBI07&state=1
                let url = location.href;
                //code=011JBI0w32eRLW2U6j4w34klDx4JBI07&state=1
                let paramStr = url.substring(url.indexOf("?")+1)
                let paramArray = paramStr.split("&"); //[code=011JBI0w32eRLW2U6j4w34klDx4JBI07,state=1]
                let resultObj = {};
                for(let i=0;i<paramArray.length;i++){
                    let tmp = paramArray[i]//code=011JBI0w32eRLW2U6j4w34klDx4JBI07
                    let paramName = tmp.split("=")[0]
                    let paramValue = tmp.split("=")[1]
                    resultObj[paramName] = paramValue;
                }
                console.log(resultObj);*/

                let paramObj = parseUrlParams(location.href);
                // console.log(paramObj)

                //发起授权请求
                // let requestObj = {"code":paramObj.code,
                //     "binderUrl":"http://bugtracker.itsource.cn/binder.html"};

                // 传递绑定地址到后端也要传递回来，可以不传递，前台写死
                let requestObj = {"code":paramObj.code};
                this.$http.post("/loginInfo/login/wechat",requestObj)
                    .then(result=>{
                        result = result.data;
                        //已经绑定登录成功，localStorage存放token,loginInfo，跳转主页
                        if(result.success){
                            let resultObj = result.resultObj;
                            localStorage.setItem("token",resultObj.token)
                            localStorage.setItem("user",JSON.stringify(resultObj.loginInfo))
                            location.href="index.html"
                        }
                        else{
                            let {accessToken,openid} = result.resultObj;
                            //没有绑定跳转绑定页面
                            location.href = "http://bugtracker.itsource.cn/binder.html?accessToken="+accessToken+"&openid="+openid;
                        }


                    })
            }
        })
    </script>
</body>
</html>